#include "registerset.h"
#include <stdlib.h>
#include <stdio.h>

/*
 * RegisterSet *new_registerset(void);
 * Constructs a new registerset and returns a pointer to it.
 */
RegisterSet *new_registerset(void)
{
	return (RegisterSet *)malloc(sizeof(RegisterSet));
}

/*
 * void registerset_initialize(RegisterSet *registerset);
 * Initializes each register in the set.
 * registerset: a pointer to the registerset to modify
 */
void registerset_initialize(RegisterSet *registerset)
{
	Register *registers = (Register *)registerset;
	
	int i;
	for (i = 0; i < REGISTERS_IN_SET; i++)
		register_initialize(registers + i);
}

/*
 * void registerset_set_register(RegisterSet *, int, unsigned short);
 * Sets the value of a register in the set.
 * registerset: a pointer to the registerset to modify
 * register_index: the 0-based index of the register to modify
 * value: the value to set the register to
 */
void registerset_set_register(RegisterSet *registerset, int register_index, unsigned short value)
{
	Register *reg = &(registerset->general_purpose_registers[register_index]);
	register_set(reg, value);
}

/*
 * unsigned short registerset_get_register(RegisterSet *registerset, int register_index);
 * Gets the value of a register in the set.
 * registerset: a pointer to the registerset to query
 * register_index: the 0-based index of the register to get the value of
 */
unsigned short registerset_get_register(RegisterSet *registerset, int register_index)
{
	Register *reg = &(registerset->general_purpose_registers[register_index]);
	return register_get(reg);
}

/*
 * void delete_registerset(RegisterSet *registerset);
 * Frees the memory associated with the register.
 * registerset: a pointer to the registerset to delete
 */
void delete_registerset(RegisterSet *registerset)
{
	free(registerset);
}
